package com.threeox.httplibrary.cookie;

import com.threeox.httplibrary.cookie.store.CookieStore;
import com.threeox.httplibrary.utils.Exceptions;

import java.util.List;

import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;

/**
 *
 * @ClassName: CookieJarImpl
 *
 * @Description: Todo()
 *
 * @author 赵屈犇
 *
 * @date 创建时间:2016/12/21 11:39
 *
 * @version 1.0
 */
public class CookieJarImpl implements CookieJar {
    private CookieStore cookieStore;

    public CookieJarImpl(CookieStore cookieStore) {
        if (cookieStore == null) Exceptions.illegalArgument("cookieStore不能为空");
        this.cookieStore = cookieStore;
    }

    @Override
    public synchronized void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
        cookieStore.add(url, cookies);
    }

    @Override
    public synchronized List<Cookie> loadForRequest(HttpUrl url) {
        return cookieStore.get(url);
    }

    public CookieStore getCookieStore() {
        return cookieStore;
    }
}
